﻿using FundHelper.Utility;
using OfficeOpenXml.Table.PivotTable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FundHelper.Model
{
    public static partial class Indicator
    {



    }

    public class ZZLResult(DateTime dateTime, double value) : IndicatorResult(dateTime, value)
    {
        [IndicatorName("zzl")]
        public override double Value => base.Value;
    }

    internal class ZZLResultCollection : MultiPeriodCollection<ZZLResult>
    {

        private ZZLResultCollection() { }

        protected override LagCollection<ZZLResult> CalPeriod(IEnumerable<ICanToTuple> his, int period)
        {
            var temp = his.ToQuote().ToArray();
            if (temp.Last().Date > temp.First().Date)
                temp = temp.OrderByDescending(a => a.Date).ToArray();

            ZZLResult[] result = new ZZLResult[temp.Length - period];

            for (int i = 0; i < result.Length; i++)
            {
                double dwjz = temp[i].Price;
                int oldIdx = i + period;
                double value = 100f * ((dwjz / temp[oldIdx].Price) - 1);
                result[i] = new ZZLResult(temp[i].Date, value);
            }
            var results = new LagCollection<ZZLResult>(result);
            return results;
        }
    }

}
